﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GroupManager.Class;

namespace GroupManager.User_Control
{
    public partial class login : System.Web.UI.UserControl
    {
        protected void HienThi(bool x,string t)
        {
            if(x)
                lblTenSauDN.Text = "Xin chào: " + t;
            else
                lblTenSauDN.Text = "";
            lblTenSauDN.Visible = x;
            lnkDangXuat.Visible = x;
            lblTenDangNhap.Visible = !x;
            lblMatKhau.Visible = !x;
            txtTenDangNhap.Visible = !x;
            txtTenDangNhap.Text = "";
            txtMatKhau.Visible = !x;
            txtMatKhau.Text = "";
            btnDangNhap.Visible = !x;
            lnkThemThanhVien.Visible = x;
            lnkThemHoatDong.Visible = x;
            lnkThemKhenThuong.Visible = x;
            lnkThemThongBao.Visible = x;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToString(Session["dn"])!="" && !IsPostBack)
            {
                HienThi(true,Session["dn"].ToString());
            }
        }

        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (txtTenDangNhap.Text!="" && txtMatKhau.Text!=""
                && LopTaiKhoan.KiemTraTaiKhoanThanhVien(txtTenDangNhap.Text)==1)
            {
                Session[0] = txtTenDangNhap.Text;
                HienThi(true, Session[0].ToString());
            }
        }

        protected void lnkDangXuat_Click(object sender, EventArgs e)
        {
            Session[0] = null;
            HienThi(false,"");
        }

        protected void lnkThemThanhVien_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ThemThanhVien.aspx");
        }

        protected void lnkThemHoatDong_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ThemHoatDong.aspx");
        }

        protected void lnkThemKhenThuong_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ThemKhenThuong.aspx");
        }

        protected void lnkThemThongBao_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ThemThongBao.aspx");
        }
    }
}